<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>在组件上用v-model</title>
    <script src='./vue.global.js'></script>
</head>
<body>
    <div id='app'>
        <!-- 
        v-model使用在子组件上，相当于：
        1、给组件注入了一个props名曰modelValue 值就是searchText对应的值
        2、接收来自子组件的自定义事件update:modelValue 处理方式就是将事件携带的数据反向同步给searchText
         -->
        <custom-input v-model="searchText"></custom-input>
    </div>

    

    <script>
        const app = Vue.createApp({

            data(){
                return {
                    searchText:"谁老婆跟人跑了？？"
                }
            }

        })

        app.component("custom-input",{
            props:["modelValue"],

            template:`
            <h3>{{modelValue}}</h3>
            <button @click="$emit('update:modelValue','他老婆跟谁跑了??')">同步</button>
            <hr/>

            <input type="text" :value="modelValue" @input="$emit('update:modelValue',$event.target.value)">
            `
        })
        
        app.mount('#app')

    </script>
</body>
</html>